//根据之前的项目，由于是不同的页面所以需要进行参数的传递，但是现在是不需要的

//指定唯一变量赋值到空间的参数中

var employeeId = "${request.getParameter('employeeId')}";
var roleId = "";
var functionUnitID = "request.getParameter('functionUnitID')";
var functionTabIndex = "request.getParameter('functionTabIndex')";
var outlookElementIndex = "request.getParameter('outlookElementIndex')";
var businessParamOutlookControls = "";//要传递的其它的业务参数，默认为空，以&开头

var businessParamTree = "";//要传递的其它的业务参数，默认为空，以&开头

var drawingId = "";
var contignationNumber = "";

//页面初始化时加载本页面所需要的参数

//@Bind #view.onCreate

!function(ajaxactionInit){
    ajaxactionInit.execute();
}

//@Bind #ajaxactionInit.onSuccess

!function(ajaxactionInit){
    var entity = ajaxactionInit.get("returnValue");
    roleId = entity.roleId;
    employeeId = entity.employeeId;
}

//点击事件，将autoform中的值传回到datasetdemand的参数中

//在制架次管理查询,通过产品图号和架次号查询相关信息

//@Bind #buttonQuery.onClick

!function(datasetDemand, datasetQuery, treeDemand, datasetProductDetail){
    var entity = datasetQuery.getData("#");
    var drawingId = entity.get("drawingId");
    var contignationNumber = entity.get("contignationNumber");
    var parentDemandUid = "null";
    datasetDemand.set("parameter", $map({
        drawingId: drawingId.replace("*", "%"),
        contignationNumber: contignationNumber.replace("*", "%"),
        parentDemandUid: "null"
    }));
    
	var taskManagerUid = employeeId;
    //重新赋值datasetProductDetail的参数

    roleId.forEach(function(en){
        if (en == "planeAssemblyManager") {
			taskManagerUid =  "%";
			return;
		}		
    });
	datasetProductDetail.set("parameter", $map({
        drawingId: drawingId.replace("*", "%"),
        batchnum: contignationNumber.replace("*", "%"),
        taskManagerUid: taskManagerUid
    }));
    datasetProductDetail.flushAsync();
    treeDemand.refresh();
    //var url = "aotree.jsp?drawingId=" + drawingId +"&batchnum="+batchnum + "&taskManagerUid=" + taskManagerUid;

    //window.open(url,"AOTreeFrame");	

}

//库存物料查询

//@Bind #buttonSearch.onClick

!function(datasetPart, datasetQuery2){
    var entity = datasetQuery2.getData("#");
    if (entity != null) {
        var drawingId = entity.get("drawingId");
        var partName = entity.get("partName");
        var partType = entity.get("classId");
        var productDeptUid = entity.get("deptId");
        datasetPart.set("parameter", $map({
            drawingId: drawingId,
            partName: partName
        }));
        
        if (entity.get("classId") == "不限") {
            datasetPart.set("parameter", $map({
                partType: "*"
            }));
        }
        else {
            datasetPart.set("parameter", $map({
                partType: partType
            }));
        }
        if (entity.get("deptId") == "不限") {
            datasetPart.set("parameter", $map({
                productDeptUid: "*"
            }));
        }
        else {
            datasetPart.set("parameter", $map({
                productDeptUid: productDeptUid
            }));
        }
    }
    datasetPart.flushAsync();
}

//@Bind @dtTask.#part_name.onGet

!function(datasetProductDetail, arg){
    //将字段拼接起来，应该获取当前实体

    var entity = arg.entity;
    var drawingId = entity.get("part_drawingId");
    var batchnum = entity.get("batchNum");
    //dorado.MessageBox.alert(drawingId);

    arg.value = drawingId + "--" + arg.value + "--" + batchnum;
}

//@Bind @dtPartTask.#part_name.onGet

!function(datasetProductDetail, arg){
    //将字段拼接起来，应该获取当前实体

    var entity = arg.entity;
    var drawingId = entity.get("part_drawingId");
    var batchnum = entity.get("batchNum");
    //dorado.MessageBox.alert(drawingId);

    arg.value = drawingId + "--" + arg.value + "--" + batchnum;
}

